package comanche.cmd;

import java.io.File;
import java.util.ArrayList;

public abstract class AbstractCommand {
	private ArrayList<String> resultLog;

	
	public AbstractCommand() {
		super();
		resultLog = new ArrayList<String>();
		append("No result to display at this time. Run the command first");
	}
	
	public final ArrayList<String> process(File f){
		clear();
		if(!f.exists()){
			manageNone();
		}
		else if(!f.isDirectory()){
			manageFile(f);
		}
		else{
			manageDirectory(f);
		}
		return resultLog;
	}
	
	protected void manageNone(){
		append("Pas de Fichier");
	}
	
	protected abstract void manageFile(File f);

	protected abstract void manageDirectory(File f);

	/**
	 * Ajoute le parametre arg dans le log des Resultat
	 * @param arg
	 */
	protected void append(String arg){
		resultLog.add(arg);
	}
	
	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	
	/**
	 * Vide le log des Resultat
	 */
	protected void clear(){
		resultLog.clear();
	}
	/**
	 * Renvoie le log des résultats
	 * @return log
	 */
	public ArrayList<String> getResultLog() {
		return resultLog;
	}
	
	public abstract String getName(); 
	 
}
